﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HammerPanel : UIBoxBase
{
    public GameObject HammerImage;
    private Vector3 hammerStartPosition = Vector3.zero;

    private void Start()
    {
        EventManager2.OnHammerSuccess += PlayHammerAnimation;

        hammerStartPosition = HammerImage.transform.position;
    }

    public void OnNumberClick()
    {
        GameManager.instance.OnHammerUse(Input.mousePosition);
    }

    private void PlayHammerAnimation(Vector3 position)
    {
        AudioController.Play("Click");
        LeanTween.move(HammerImage, Camera.main.WorldToScreenPoint(position) - new Vector3(100f,0,0), 0.7f).setEase(LeanTweenType.easeInOutQuad).setOnComplete(() =>
        {
            LeanTween.rotateZ(HammerImage, -45f, 0.3f).setEase(LeanTweenType.easeInBack).setOnComplete(()=>{
                AudioController.Play("Burst");
                HideBox();
                UIManager.instance.ShowBox(UIBoxType.MainPanel);
                HammerImage.transform.position = hammerStartPosition;
                HammerImage.transform.rotation = Quaternion.identity;
            });
        });
    }

    public void OnCloeButtonClick()
    {
        HideBox();
        UIManager.instance.ShowBox(UIBoxType.MainPanel);
    }
}
